import EaseInOut from "@/libs/easeInOut";
import type { ActionContext } from "vuex";
import { RootState } from ".";


export type LayoutMainState = {

}
export type LayoutMainContext = ActionContext<LayoutMainState, RootState>


const state: LayoutMainState = {
}

const mutations = {

}

const actions = {
  MAINSCROLLTOTOP(ctx: LayoutMainContext, targetId: string) {
    let main = document.getElementById('CBC-main')
    let targetoffsetHeight = 0
    if (targetId) {
      let targetDom = document.getElementById(targetId)
      targetoffsetHeight = targetDom?.offsetHeight || 0
      console.log('目标元素的offsetHeight', targetoffsetHeight);
    }
    if (main) {
      let scrollTop = targetoffsetHeight || main.scrollTop
      console.log(scrollTop);
      if (!scrollTop || scrollTop <= 0) return
      new EaseInOut({
        autoplay: true,
        startVal: scrollTop,
        endVal: 0,
        duration: 500,
        running(val) {
          main?.scrollTo(0, val)
        }
      })
    }
  }
}

const getters = {
}

export default {
  namespaced: true, // 声明命名空间
  state,
  mutations,
  actions,
  getters
}